var flag=0;
var v=0;
var ddd;
function add(S,e){
if(v==0){
  ddd=document.getElementById("d8");
  v++;
}
  var c=document.getElementById("c").checked;
  var c1=document.getElementById("c1").checked;
  var c2=document.getElementById("c2").checked;
  if(S=="张某某"&&c||S=="李某某"&&c1||S=="王某某"&&c2){
     var arry=[{"name":"张某某","Type":"身份证","Cno":"4222826199805316548"},
               {"name":"李某某","Type":"身份证","Cno":"422826195408215679"},
               {"name":"王某某","Type":"身份证","Cno":"422826195506237635"}];
    if(flag==0){
         var i=0;
         for(i=0;arry.length;i++){
            if(arry[i].name==S){
                break;
            }
         }
         var div=document.getElementsByTagName("input");
      for(j=0;j<div.length;j++){
        if(div[j].getAttribute('id') == 't'){
            div[j].setAttribute('class', 't')
        }
      }
      var di=document.getElementsByTagName("input");
      for(j=0;j<di.length;j++){
        if(di[j].getAttribute('id') == 't1'){
            di[j].setAttribute('class', 't1')
        }
      } 
      //var ddd=document.getElementById("d8")
      console.log(ddd);
         ddd.setAttribute("class",S);
         var t=document.getElementsByClassName("t");
         var t1=document.getElementsByClassName("t1");
         var name=arry[i].name;
         t[flag].setAttribute("value",name);
         var cno=arry[i].Cno;
          t1[flag].setAttribute("value",cno);
         flag++;
         v=S;
    }
  else if(flag==1||flag==2){
      //☆
      var div=document.getElementsByTagName("input");
      for(i=0;i<div.length;i++){
        if(div[i].getAttribute('id') == 't'){
            div[i].setAttribute('class', 't')
        }
      }
      var div=document.getElementsByTagName("input");
      for(i=0;i<div.length;i++){
        if(div[i].getAttribute('id') == 't1'){
            div[i].setAttribute('class', 't1')
        }
      }
      //
      var dv=document.getElementsByTagName("span");
      for(i=0;i<dv.length;i++){
        if(dv[i].getAttribute('id') == 's23'){
            dv[i].setAttribute('class', 'sss')
        }
      }
    var newdiv=document.createElement("div");
    newdiv.setAttribute("id","d8"+flag);
    var dd=document.getElementById("dd");
    var html=ddd.innerHTML;
    newdiv.innerHTML=html;
    dd.appendChild(newdiv);
    var i=0;
         for(i=0;arry.length;i++){
            if(arry[i].name==S){
                break;
            }
         }
         var d=document.getElementsByClassName("t");//☆
         var name=arry[i].name;
         d[flag].setAttribute("value",name);//☆
         var cno=arry[i].Cno;
         var t=document.getElementsByClassName("t1");
          t[flag].setAttribute("value",cno);
          var sss=document.getElementsByClassName("sss");
          var fl;
          if(flag==1){
            fl="二";
          }
          if(flag==2){
            fl="三"
          }
          sss[flag].innerHTML="第"+fl+"位乘机人：";
           var dp=document.getElementById("d8"+flag)
         dp.setAttribute("class",S);
         flag++;
         v=S;
  }
  else if(flag>2){
    alert("您好！本网站只允许3人同时购买");
    return 0;
}
  }
  else{
    remove(S,e);
  }
}
function ad(){
    if(flag<=2){
    // var d8=document.getElementById("d8");
    var newdiv=document.createElement("div");
    newdiv.setAttribute("id","d8"+flag);
    var dd=document.getElementById("dd");
    var html=ddd.innerHTML;
    newdiv.innerHTML=html;
    dd.appendChild(newdiv);
    var div=document.getElementsByTagName("input");
      for(i=0;i<div.length;i++){
        if(div[i].getAttribute('id') == 't'){
            div[i].setAttribute('class', 't')
        }
      }
      var di=document.getElementsByTagName("input");
      for(i=0;i<di.length;i++){
        if(di[i].getAttribute('id') == 't1'){
            di[i].setAttribute('class', 't1')
        }
      }
      var dv=document.getElementsByTagName("span");
      for(i=0;i<dv.length;i++){
        if(dv[i].getAttribute('id') == 's23'){
            dv[i].setAttribute('class', 'sss')
        }
      }
      var sss=document.getElementsByClassName("sss");
      
     var fl;
     if(flag==0){
        flag=1;
        fl="二";
     }
      if(flag==1){
        fl="二";
      }
      if(flag==2){
        fl="三"
      }
      sss[flag].innerHTML="第"+fl+"位乘机人：";
      var t=document.getElementsByClassName("t");
      t[flag].setAttribute("value"," ");
      var t1=document.getElementsByClassName("t1");
      t1[flag].setAttribute("value"," ");
      flag++;
    }
    else if(flag>2){
    alert("您好！本网站只允许3人同时购买");
    return 0;
    }
}